package 力扣日常刷题.木23一月.第20天320;

import java.util.PriorityQueue;

public class Demo108数组减少一半 {

    public int halveArray(int[] nums) {
        long sum = 0;
        double res = 0;
        double target = 0;
        int count = 0;
        PriorityQueue<Double> que = new PriorityQueue<>((a,b)->Double.compare(b,a));

        for (int i = 0; i < nums.length; i++) {
            sum += nums[i];
            que.add(nums[i] * 1.0);
        }
        target = sum * 1.0 / 2;

        while(res < target) {
            double temp = que.poll();
            res += temp/2;
            que.add(temp/2);
            count ++;
        }
        return count;
    }
}
